//
//  HDNavigationController.swift
//  个人微博
//
//  Created by 爱生活Geek on 16/10/21.
//  Copyright © 2016年 爱生活. All rights reserved.
//

import UIKit

class HDNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? HDBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    
                    title = childViewControllers.first?.title ?? "返回"
                }
                
//                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popBack))
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(popBack))
            }
            
        }
        
        super.pushViewController(viewController, animated: true)
    }
    @objc private func popBack(){
        self.popViewController(animated: true)
    }
}
